<?php

class Common_DataTable_Model_Mixin_HeaderDetector {

    public function detectHeaders($arr_data) {
    
        $arr_headers = null;
        
        if(is_array($arr_data)) {
            
            $arr_headers = array();
            foreach($arr_data as $str_column_key => $mix_value) {
                $arr_headers[$str_column_key] = $this->detectHeaderDefinition($str_column_key, $mix_value);
            }
            
            $arr_headers = array($arr_headers);
            
        }
        
        return $arr_headers;
        
    }
    
    public function detectHeaderDefinition($str_column_key, $mix_value = null) {
        
        $str_label = ucwords(str_replace(array('_', '-', '.'), ' ', $str_column_key));
        
        $arr_header_definition = array(
            'label' => $str_label
        );
        
        if(!is_null($mix_value) && is_numeric($mix_value)) {
            $arr_header_definition['class']  = 'number';
            $arr_header_definition['type']   = 'number';
            $arr_header_definition['format'] = 'number';
        }
        
        if(stripos($str_column_key, 'currency') !== false) {
            $arr_header_definition['format'] = 'currency';
            $arr_header_definition['format_options'] = array(
                'precision' => 2
            );
        }
        
        if(stripos($str_column_key, 'percent') !== false) {
            $arr_header_definition['format'] = 'percentage';
            $arr_header_definition['format_options'] = array(
                'scale' => 100
            );
        }
        
        if(stripos($str_column_key, 'boolean') !== false) {
            $arr_header_definition['format'] = 'boolean';
        }
        
        return $arr_header_definition;
        
    }

}
